<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        *{
            padding: 0;
            margin: 0;
        }
        ul{
            list-style: none;
        }
        .tab{
            padding: 20px;
            width: 500px;
            border: 1px solid black;
        }
        .tab-nav{
            display: flex;
            height: 30px;
            margin-bottom: 20px;
            justify-content: space-between;
            line-height: 30px;
        }
        .tab-nav ul{
            display: flex;
        }
        .tab-nav ul li{
            margin: 0px 10px;
        }
        .tab-nav ul li a{
            color: black;
            text-decoration: none;
            border-bottom: 2px solid transparent;
        }
        .tab-nav ul li a.active{
             border-color: red;
             color: red;
        }
        .tab-content .item img{
            width: 500px;
            display: block;
        }
        .tab-content .item{
            display: none;
        }
        .tab-content .active{
            display: block;
        }
    </style>
</head>
<body>
    <div class="tab">
        <div class="tab-nav">
            <h2>兰盺硕</h2>
            <ul>
                <li><a href="#" class="active">精选</a></li>
                <li><a href="#">美食</a></li>
                <li><a href="#">百货</a></li>
                <li><a href="#">个护</a></li>
                <li><a href="#">预告</a></li>
            </ul>
        </div>
        <div class="tab-content">
            <div class="item active"><img src="../第五单元作业/images/course01.png"></div>
            <div class="item"><img src="../第五单元作业/images/course02.png"></div>
            <div class="item"><img src="../第五单元作业/images/course03.png"></div>
            <div class="item"><img src="../第五单元作业/images/course04.png"></div>
            <div class="item"><img src="../第五单元作业/images/course05.png"></div>
        </div>
    </div>

    <script>
         const as = document.querySelectorAll('.tab-nav a')
         for(let i =0;i<as.length;i++){
            as[i].addEventListener('click',function(){
                //点击删除类名active，然后将给每个被点击的a标签添加类名active
                document.querySelector('.tab-nav .active').classList.remove('active')
                as[i].classList.add('active')
                //同上，先删除类名
                document.querySelector('.tab-content .active').classList.remove('active')
                //但是，此时要使用i将图片与点击的导航栏进行关
                document.querySelector(`.tab-content .item:nth-child(${i+1})`).classList.add('active')
            })
         }
    </script>
</body>
</html>